﻿namespace Chain.BLL
{
    using Chain.IDAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class GoodsAllot
    {
        private readonly Chain.IDAL.GoodsAllot dal = new Chain.IDAL.GoodsAllot();

        public int Add(Chain.Model.GoodsAllot model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.GoodsAllot> DataTableToList(DataTable dt)
        {
            List<Chain.Model.GoodsAllot> list = new List<Chain.Model.GoodsAllot>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.GoodsAllot item = new Chain.Model.GoodsAllot();
                    if ((dt.Rows[i]["AllotID"] != null) && (dt.Rows[i]["AllotID"].ToString() != ""))
                    {
                        item.AllotID = int.Parse(dt.Rows[i]["AllotID"].ToString());
                    }
                    if ((dt.Rows[i]["AllotAccount"] != null) && (dt.Rows[i]["AllotAccount"].ToString() != ""))
                    {
                        item.AllotAccount = dt.Rows[i]["AllotAccount"].ToString();
                    }
                    if ((dt.Rows[i]["AllotOutShopID"] != null) && (dt.Rows[i]["AllotOutShopID"].ToString() != ""))
                    {
                        item.AllotOutShopID = int.Parse(dt.Rows[i]["AllotOutShopID"].ToString());
                    }
                    if ((dt.Rows[i]["AllotInShopID"] != null) && (dt.Rows[i]["AllotInShopID"].ToString() != ""))
                    {
                        item.AllotInShopID = int.Parse(dt.Rows[i]["AllotInShopID"].ToString());
                    }
                    if ((dt.Rows[i]["AllotCreateTime"] != null) && (dt.Rows[i]["AllotCreateTime"].ToString() != ""))
                    {
                        item.AllotCreateTime = DateTime.Parse(dt.Rows[i]["AllotCreateTime"].ToString());
                    }
                    if ((dt.Rows[i]["AllotTotalNumber"] != null) && (dt.Rows[i]["AllotTotalNumber"].ToString() != ""))
                    {
                        item.AllotTotalNumber = decimal.Parse(dt.Rows[i]["AllotTotalNumber"].ToString());
                    }
                    if ((dt.Rows[i]["AllotUserID"] != null) && (dt.Rows[i]["AllotUserID"].ToString() != ""))
                    {
                        item.AllotUserID = int.Parse(dt.Rows[i]["AllotUserID"].ToString());
                    }
                    if ((dt.Rows[i]["AllotRemark"] != null) && (dt.Rows[i]["AllotRemark"].ToString() != ""))
                    {
                        item.AllotRemark = dt.Rows[i]["AllotRemark"].ToString();
                    }
                    if ((dt.Rows[i]["AllotState"] != null) && (dt.Rows[i]["AllotState"].ToString() != ""))
                    {
                        item.Allotstate = int.Parse(dt.Rows[i]["AllotState"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int AllotID)
        {
            return this.dal.Delete(AllotID);
        }

        public bool DeleteList(string AllotIDlist)
        {
            return this.dal.DeleteList(AllotIDlist);
        }

        public bool Exists(int AllotID)
        {
            return this.dal.Exists(AllotID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public DataSet GetListSP(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP(PageSize, PageIndex, out resCount, strWhere);
        }

        public Chain.Model.GoodsAllot GetModel(int AllotID)
        {
            return this.dal.GetModel(AllotID);
        }

        public List<Chain.Model.GoodsAllot> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public bool Update(Chain.Model.GoodsAllot model)
        {
            return this.dal.Update(model);
        }
    }
}

